# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
from selenium import webdriver
import json

class www_test:
    status_404 = '404'
    driver = ""
    filted = "http://"
    
    def __init__(self):
#        options = webdriver.ChromeOptions()
#
#        options.add_argument('headless')
#        options.add_argument('window-size=1200x600')
#        self.driver = webdriver.Chrome(chrome_options=options)
        self.driver = webdriver.Chrome()
    
    def get_http_status(self, url):
        self.driver.get(url)
        print(self.driver.page_source)
        for responseReceived in self.driver.get_log('browser'):
            if self.status_404 in responseReceived["message"]:
                return self.status_404
        return None
    
    def get_src_url(self):
        all_url = []
        for image in self.driver.find_elements_by_tag_name("img"):
            src_link = image.get_attribute('src')
            if self.filted in str(src_link) :
                all_url.append(str(src_link))
        return all_url

    def get_js_url(self):
        all_url = []
        for script in self.driver.find_elements_by_tag_name("script"):
#            script_link = script.get_attribute('src')
            print(script)
            print(script.text)
#            all_url.append(str(script_link))  
        return all_url
            
    def get_css_url(self):
        all_url = []
        for link in self.driver.find_elements_by_tag_name("link"):
            link_link = link.get_attribute('href')
            all_url.append(str(link_link)) 
        return all_url
    
    def all_http(self):
        all_url = []
        for image in self.driver.find_elements_by_tag_name("img"):
            src_link = image.get_attribute('src')
            all_url.append(str(src_link))
        
        for href in self.driver.find_elements_by_tag_name("a"):
            href_link = href.get_attribute('href')
            all_url.append(str(href_link))
            
        for script in self.driver.find_elements_by_tag_name("script"):
            script_link = script.get_attribute('src')
            all_url.append(str(script_link))    
            
        for link in self.driver.find_elements_by_tag_name("link"):
            link_link = link.get_attribute('href')
            all_url.append(str(link_link)) 
        return all_url
        
